package cn.wolfcode.crm.service.impl;

import cn.wolfcode.crm.domain.Department;
import cn.wolfcode.crm.mapper.DepartmentMapper;
import cn.wolfcode.crm.query.QueryObject;
import cn.wolfcode.crm.service.IDepartmentService;
import cn.wolfcode.crm.util.PageResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Collections;
import java.util.List;

@Service
public class DepartmentServiceImpl implements IDepartmentService {
    @Autowired
    private DepartmentMapper departmentMapper;


    public int insert(Department record) {

        return departmentMapper.insert(record);
    }

    public int updateByPrimaryKey(Department record) {

        return departmentMapper.updateByPrimaryKey(record);
    }


    public List<Department> selectAll() {

        return departmentMapper.selectAll();
    }

    public PageResult query(QueryObject qo) {
        int total = departmentMapper.query4Count(qo);
        if(total > 0){
            return new PageResult(total,departmentMapper.query4List(qo));
        }
        return new PageResult(total, Collections.EMPTY_LIST);
    }

    public int deleteByPrimaryKey(Long id) {

        return departmentMapper.deleteByPrimaryKey(id);
    }
}
